<div class="container">
	<form method="post" id="formuser" action="#" class="form-horizontal" role="form"> 
	<div class="col-md-offset-1">
		<div class="col-md-11">
			<div class="panel panel-default">
				<div class="panel-heading"><h4 class="panel-title"><b class="caret"></b><b> Request By</b></h4></div>
				<div class="panel-body">
					<div class="col-xs-12 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-4">Name<span style="color:red;">*</span></label>
							<div class="col-md-7"><input type="text" value="" id="r_name" class="select2 form-control input-sm">
							<input type="hidden" value="" id="r_nama" class="select2 form-control input-sm" readonly="true"/></div>
						</div>					
						<div class="form-group">
							<label class="control-label col-md-4">ID Number</label>
							<div class="col-md-3"><input type="text" value="" id="r_id" class="form-control input-sm" readonly="true"/></div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">Manager</label>
							<div class="col-md-7"><input type="text" value="" id="r_mgr" class="form-control input-sm" readonly="true"/>
							<input type="hidden" value="" id="r_mgrid" class="form-control input-sm" readonly="true"/></div>
						</div>
					</div>
					<div class="col-sm-7 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-4">Departement</label>
							<div class="col-md-7"><input type="text" value="" id="r_dept" class="form-control input-sm" readonly="true"/></div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">Job Position</label>
							<div class="col-md-8"><input type="text" value="" id="r_job" class="form-control input-sm" readonly="true"/></div>
						</div>
					</div>
				</div>
			</div>
			<div class="panel panel-default">
				<div class="panel-heading">
					<h4 class="panel-title"><b class="caret"></b><b> Form</b></h4>
				</div>
				<div class="panel-body">
					<div class="col-sm-7 col-md-6">
						<div class="form-group">
							<label for="type" class="control-label col-md-4">Type<span style="color:red;">*</span></label>
							<div class="col-md-6">
								<select id="type_name" name="type_name" required="required" class="form-control input-sm" onchange="javascript:getRoom()" />                         
									<option value="0">-- select --</option>
								<?php
									if (!empty($type_name)) { 
										foreach($type_select as $type_select => $key)
										{ ?>
											<option value="<?php echo $key['MST_TYPE_ID']; ?>"<?php echo (strtoupper($type_name) == strtoupper($key['MST_TYPE_ID'])) ? 'selected' : ''; ?>><?php echo $key['MST_TYPE_DESC']; ?></option>									
										<?php
										}
									} else {
										foreach($type_select as $type_select => $key)
										{ ?>
											<option value="<?php echo $key['MST_TYPE_ID']; ?>"><?php echo $key['MST_TYPE_DESC']; ?></option>									
										<?php
											//echo '<option value="'.$key['MST_TYPE_ID'].'">'.$key['MST_TYPE_DESC'].'</option>';
										}		
									}
								?>
								</select>								
							</div>
						</div>
						<div class="form-group" id="room_select">
							<label for="room" class="control-label col-md-4">Room Name<span style="color:red;">*</span></label>
							<div class="col-md-6">
								<!--Updated by Surya Alam Gultom /-->
								<select id="room_name" required="required" class="form-control input-sm" />                         
									<?php
									if (!empty($room_name)) { ?>
										<option value="0">-- select --</option>
										<option value="<?php echo $room_name; ?>"<?php echo ($room_name == $room_name) ? 'selected' : ''; ?>>
											<?php echo $room_name; ?>
										</option>										
									<?php										
									} else {
									?>
										<option readonly="true" value="0">-- select type first --</option>											
									<?php
									} ?>
								</select>
							</div>
						</div>
						<div class="form-group" id="floor_select">
							<label for="lantai" class="control-label col-md-4">Floor</label>
							<div class="col-md-7">
								<select id="floor" class="form-control input-sm">
									<?php /* 
									foreach ($ShowFloor AS $ShowFloor)
									{
										echo '<option value= '.$ShowFloor['MST_FLOOR_DESC'].'>'.$ShowFloor['MST_FLOOR_DESC'].'</option>';
									}; */ ?>
									<option readonly="true" value="0">-- select room name first --</option>
								</select>								
							</div>								
						</div>
						<div class="form-group">
							<label for="serial" class="control-label col-md-4">Serial#</label>
							<div class="col-md-7"><input type="text" value="" required="required" id="serial" class="form-control input-sm" /></div>
						</div>
					</div>
					<div class="col-sm-7 col-md-6">
						<div class="form-group">
							<label for="req_date" class="control-label col-md-5">Request Date<span style="color:red;">*</span></label>
							<div class="col-md-4">
								<div class="input-group">
									<input type="text" class="form-control input-sm" name="G_Date1" id="G_Date1" value="<?php echo $dtNow; ?>">
									<!--span class="input-group-addon" style="cursor:pointer" id="image_button"><span class="glyphicon glyphicon-calendar"></span></span-->
								</div>
							</div>
						</div>
						<div class="form-group">
							<label for="prom_date" class="control-label col-md-5">Promise Date<span style="color:red;">*</span></label>
							<div class="col-md-4">
								<div class="input-group">
									<input type="text" class="form-control input-sm" name="G_Date2" id="G_Date2" value="<?php echo $dtNow; ?>">
									<!--span class="input-group-addon" style="cursor:pointer" id="image_button"><span class="glyphicon glyphicon-calendar"></span></span-->
								</div>
							</div>
						</div>
						<div class="form-group">
							<label for="description" class="control-label col-md-5">Description<span style="color:red;">*</span></label>
							<div class="col-md-7">
								<textarea name="Desc" id="Desc" class="form-control input-sm" required="required" style="min-width:190px;max-width:200px;min-height:100px;max-height:200px;"></textarea>
							</div>
						</div>
					</div>
					<div class="form-group" style="text-align:center">				
						<input type="submit" value="Save This Form" name="submit" id="btn_submitform" class="btn btn-md btn-success" />
						<!--button type="button" class="btn btn-success btn-md">Save This Form</button-->
					</div>
				</div>
			</div>
		</div>
	</div>
	</form>
</div>

<script type="text/javascript">
    $.validator.setDefaults({
        submitHandler: function() {
            $.post("<?= site_url() ?>work_facility/insert_rm", {
                r_id		: $('#r_id').val(), 
				r_name		: $('#r_name').val(), 
				r_mgr		: $('#r_mgr').val(), 
				r_dept		: $('#r_dept').val(), 
				r_job		: $('#r_job').val(), 
				type_name	: $('#type_name').val(), 
				room_name	: $('#room_name').val(), 
				floor		: $('#floor').val(), 
				serial		: $('#serial').val(), 
				G_Date1		: $('#G_Date1').val(), 
				G_Date2		: $('#G_Date2').val(), 
                Desc		: $('#Desc').val() 
            },
            function(data) {
                //window.location = '<?php echo base_url();?>work_facility/repair_and_maintenance';
            });
        }
    });

    $(document).ready(function() {
        $("#formuser").keypress(function(e) {
            if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                $.validator.setDefaults({
                    submitHandler: function() {
                        $.post("<?= site_url() ?>work_facility/insert_rm", {
                            r_id		: $('#r_id').val(), 
							r_name		: $('#r_name').val(), 
							r_mgr		: $('#r_mgr').val(), 
							r_dept		: $('#r_dept').val(), 
							r_job		: $('#r_job').val(), 
							type_name	: $('#type_name').val(), 
							room_name	: $('#room_name').val(), 
							floor		: $('#floor').val(), 
							serial		: $('#serial').val(), 
							G_Date1		: $('#G_Date1').val(), 
							G_Date2		: $('#G_Date2').val(), 
							Desc		: $('#Desc').val() 
                        },
                        function(data) {
                            //window.location = '<?php echo base_url();?>work_facility/repair_and_maintenance';
                        });
                    }
                });
            }
        });

        $("#formuser").validate();
    });

	function getRoom()
	{
		var type_name = {type_name:$("#type_name").val()};
		$.ajax({
				type: "POST",
				url : "<?php echo site_url('work_facility/ShowRoomRequest');?>",
				data: type_name,
				success: function(msg){$('#room_select').html(msg);}
			});
	};
	
	function getFloor()
	{
		var room_name = {room_name:$("#room_name").val()};
		$.ajax({
				type: "POST",
				url : "<?php echo site_url('work_facility/ShowFloorRequest');?>",
				data: room_name,
				success: function(msg){$('#floor_select').html(msg);}
			});
	};
</script>
